home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / UPDATE- Int&Libs 3.2 / CIncludes / Multiprocessing.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-25  |  25.1 KB  |  841 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Multiprocessing.h
  3.  
  4.      Contains:    Multiprocessing interfaces
  5.  
  6.      Version:    Technology:    Multiprocessing API version 2.0, integrated nanokernel support
  7.                  Release:    Veronica Seed, Use with 3.2 Universal Interfaces
  8.  
  9.      Copyright:    © 1996-1999 by Apple Computer, Inc. and © 1995-1997 DayStar Digital, Inc.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. /*
  18.    ===========================================================================================
  19.    *** WARNING: You must properly check the availability of MP services before calling them!
  20.    See the section titled "Checking API Availability".
  21.    ===========================================================================================
  22. */
  23.  
  24.  
  25. #ifndef __MULTIPROCESSING__
  26. #define __MULTIPROCESSING__
  27.  
  28. #ifndef __MACTYPES__
  29. #include <MacTypes.h>
  30. #endif
  31. #ifndef __CODEFRAGMENTS__
  32. #include <CodeFragments.h>
  33. #endif
  34.  
  35. #ifndef __DRIVERSERVICES__
  36. #include <DriverServices.h>
  37. #endif
  38.  
  39.  
  40.  
  41.  
  42. #if PRAGMA_ONCE
  43. #pragma once
  44. #endif
  45.  
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49.  
  50. #if PRAGMA_IMPORT
  51. #pragma import on
  52. #endif
  53.  
  54. #if PRAGMA_STRUCT_ALIGN
  55.     #pragma options align=power
  56. #elif PRAGMA_STRUCT_PACKPUSH
  57.     #pragma pack(push, 2)
  58. #elif PRAGMA_STRUCT_PACK
  59.     #pragma pack(2)
  60. #endif
  61.  
  62. /*
  63.    ===========================================================================================
  64.    This is the header file for version 2.0 of the Mac OS multiprocessing support.  This version
  65.    has been totally reimplemented and has significant new services.  The main goal of the
  66.    reimplementation has been to transfer task management into the core operating system to provide
  67.    much more reliable and more efficient operation, including on single processor machines.
  68.    The memory management has also been massively improved, it is much faster and wastes much
  69.    less space.  New services include POSIX style per-task storage, timers with millisecond and
  70.    microsecond resolutions, memory allocation at a specified alignment, and system pageable
  71.    and RAM resident memory pools.  See the MP API documentation for details.
  72.    The old "DayStar" debugging services (whose names began with an underscore) have been
  73.    removed from this header.  A very few are still implemented for binary compatibility, or in
  74.    cases where they happened to be exposed inappropriately.  (E.g. _MPIsFullyInitialized must
  75.    be called to see if the MP API is ReallyTruly™ usable.)  New code and recompiles of old
  76.    code should avoid use of these defunct services, except for _MPIsFullyInitialized.
  77.    ===========================================================================================
  78. */
  79.  
  80.  
  81. /*
  82.    ===========================================================================================
  83.    The following services are from the original MP API and remain supported in version 2.0:
  84.       MPProcessors
  85.       MPCreateTask
  86.       MPTerminateTask
  87.       MPCurrentTaskID
  88.       MPYield
  89.       MPExit
  90.       MPCreateQueue
  91.       MPDeleteQueue
  92.       MPNotifyQueue
  93.       MPWaitOnQueue
  94.       MPCreateSemaphore
  95.       MPCreateBinarySemaphore        (In C only, a macro that calls MPCreateSemaphore.)
  96.       MPDeleteSemaphore
  97.       MPSignalSemaphore
  98.       MPWaitOnSemaphore
  99.       MPCreateCriticalRegion
  100.       MPDeleteCriticalRegion
  101.       MPEnterCriticalRegion
  102.       MPExitCriticalRegion
  103.       MPAllocate                    (Deprecated, use MPAllocateAligned for new builds.)
  104.       MPFree
  105.       MPBlockCopy
  106.       MPLibraryIsLoaded            (In C only, a macro.)
  107.       _MPIsFullyInitialized        (See comments about checking for MP API availability.)
  108.    ===========================================================================================
  109. */
  110.  
  111.  
  112. /*
  113.    ===========================================================================================
  114.    The following services are new in version 2.0:
  115.       MPProcessorsScheduled
  116.       MPSetTaskWeight
  117.       MPTaskIsPreemptive
  118.       MPAllocateTaskStorageIndex
  119.       MPDeallocateTaskStorageIndex
  120.       MPSetTaskStorageValue
  121.       MPGetTaskStorageValue
  122.       MPSetQueueReserve
  123.       MPCreateEvent
  124.       MPDeleteEvent
  125.       MPSetEvent
  126.       MPWaitForEvent
  127.       UpTime
  128.       DurationToAbsolute
  129.       AbsoluteToDuration
  130.       MPDelayUntil
  131.       MPCreateTimer
  132.       MPDeleteTimer
  133.       MPSetTimerNotify
  134.       MPArmTimer
  135.       MPCancelTimer
  136.       MPSetExceptionHandler
  137.       MPThrowException
  138.       MPDisposeTaskException
  139.       MPExtractTaskState
  140.       MPSetTaskState
  141.       MPRegisterDebugger
  142.       MPUnregisterDebugger
  143.       MPAllocateAligned            (Preferred over MPAllocate.)
  144.       MPGetAllocatedBlockSize
  145.       MPBlockClear
  146.       MPDataToCode
  147.       MPRemoteCall                (Preferred over _MPRPC.)
  148.    ===========================================================================================
  149. */
  150.  
  151.  
  152. /*
  153.    ===========================================================================================
  154.    The following services are "unofficial" extensions to the original API.  They are not in
  155.    the multiprocessing API documentation, but were in previous versions of this header.  They
  156.    remain supported in version 2.0.  They may not be supported in other environments.
  157.       _MPRPC                        (Deprecated, use MPRemoteCall for new builds.)
  158.       _MPAllocateSys                (Deprecated, use MPAllocateAligned for new builds.)
  159.       _MPTaskIsToolboxSafe
  160.       _MPLibraryVersion
  161.       _MPLibraryIsCompatible
  162.    ===========================================================================================
  163. */
  164.  
  165.  
  166. /*
  167.    ===========================================================================================
  168.    The following services were in previous versions of this header for "debugging only" use.
  169.    They are NOT implemented in version 2.0.  For old builds they can be accessed by defining
  170.    the symbol MPIncludeDefunctServices to have a nonzero value.
  171.       _MPInitializePrintf
  172.       _MPPrintf
  173.       _MPDebugStr
  174.       _MPStatusPString
  175.       _MPStatusCString
  176.    ===========================================================================================
  177. */
  178.  
  179.  
  180. /*
  181.    §
  182.    ===========================================================================================
  183.    General Types and Constants
  184.    ===========================
  185. */
  186.  
  187.  
  188. #define MPCopyrightNotice    \
  189.     "Copyright © 1995-1999 Apple Computer, Inc.\n"
  190. #define MPLibraryName "MPLibrary"
  191. #define MPLibraryCName MPLibraryName
  192. #define MPLibraryPName "\p" MPLibraryName
  193. #define MP_API_Version "2.0"
  194.  
  195. enum {
  196.     MPLibrary_MajorVersion        = 2,
  197.     MPLibrary_MinorVersion        = 0,
  198.     MPLibrary_Release            = 1,
  199.     MPLibrary_DevelopmentRevision = 1
  200. };
  201.  
  202.  
  203. typedef CFragContextID                     MPProcessID;
  204. typedef struct OpaqueMPTaskID*             MPTaskID;
  205. typedef struct OpaqueMPQueueID*         MPQueueID;
  206. typedef struct OpaqueMPSemaphoreID*     MPSemaphoreID;
  207. typedef struct OpaqueMPCriticalRegionID*  MPCriticalRegionID;
  208. typedef struct OpaqueMPTimerID*         MPTimerID;
  209. typedef struct OpaqueMPEventID*         MPEventID;
  210. typedef struct OpaqueMPAddressSpaceID*     MPAddressSpaceID;
  211. typedef struct OpaqueMPOpaqueID*         MPOpaqueID;
  212. enum {
  213.     kMPNoID                        = kInvalidID                    /* New code should use kInvalidID everywhere.*/
  214. };
  215.  
  216.  
  217. typedef OptionBits                         MPTaskOptions;
  218. typedef UInt32                             TaskStorageIndex;
  219. typedef UInt32                             TaskStorageValue;
  220. typedef ItemCount                         MPSemaphoreCount;
  221. typedef UInt32                             MPTaskWeight;
  222. typedef UInt32                             MPEventFlags;
  223. typedef UInt32                             MPExceptionKind;
  224. typedef UInt32                             MPTaskStateKind;
  225. typedef UInt32                             MPDebuggerLevel;
  226. enum {
  227.     kDurationImmediate            = 0L,
  228.     kDurationForever            = 0x7FFFFFFF,
  229.     kDurationMillisecond        = 1,
  230.     kDurationMicrosecond        = -1
  231. };
  232.  
  233.  
  234. /*
  235.    §
  236.    ===========================================================================================
  237.    Tasking Services
  238.    ================
  239. */
  240.  
  241.  
  242. EXTERN_API_C( ItemCount )
  243. MPProcessors                    (void);
  244.  
  245. /* The physical total.*/
  246. EXTERN_API_C( ItemCount )
  247. MPProcessorsScheduled            (void);
  248.  
  249. /* Those currently in use.*/
  250. typedef CALLBACK_API_C( OSStatus , TaskProc )(void *parameter);
  251. /* -------------------------------------------------------------------------------------------*/
  252.  
  253.  
  254. EXTERN_API_C( OSStatus )
  255. MPCreateTask                    (TaskProc                 entryPoint,
  256.                                  void *                    parameter,
  257.                                  ByteCount                 stackSize,
  258.                                  MPQueueID                 notifyQueue,
  259.                                  void *                    terminationParameter1,
  260.                                  void *                    terminationParameter2,
  261.                                  MPTaskOptions             options,
  262.                                  MPTaskID *                task);
  263.  
  264. EXTERN_API_C( OSStatus )
  265. MPTerminateTask                    (MPTaskID                 task,
  266.                                  OSStatus                 terminationStatus);
  267.  
  268. EXTERN_API_C( OSStatus )
  269. MPSetTaskWeight                    (MPTaskID                 task,
  270.                                  MPTaskWeight             weight);
  271.  
  272. EXTERN_API_C( Boolean )
  273. MPTaskIsPreemptive                (MPTaskID                 taskID);
  274.  
  275. /* May be kInvalidID.*/
  276. EXTERN_API_C( void )
  277. MPExit                            (OSStatus                 status);
  278.  
  279. EXTERN_API_C( void )
  280. MPYield                            (void);
  281.  
  282. EXTERN_API_C( MPTaskID )
  283. MPCurrentTaskID                    (void);
  284.  
  285.  
  286. /* -------------------------------------------------------------------------------------------*/
  287.  
  288.  
  289. /*
  290.    ---------------------------------------------------
  291.    ! The task storage services are new in version 2.0.
  292. */
  293.  
  294.  
  295. EXTERN_API_C( OSStatus )
  296. MPAllocateTaskStorageIndex        (TaskStorageIndex *        index);
  297.  
  298. EXTERN_API_C( OSStatus )
  299. MPDeallocateTaskStorageIndex    (TaskStorageIndex         index);
  300.  
  301. EXTERN_API_C( OSStatus )
  302. MPSetTaskStorageValue            (TaskStorageIndex         index,
  303.                                  TaskStorageValue         value);
  304.  
  305. EXTERN_API_C( TaskStorageValue )
  306. MPGetTaskStorageValue            (TaskStorageIndex         index);
  307.  
  308.  
  309. /*
  310.    §
  311.    ===========================================================================================
  312.    Synchronization Services
  313.    ========================
  314. */
  315.  
  316.  
  317. EXTERN_API_C( OSStatus )
  318. MPCreateQueue                    (MPQueueID *            queue);
  319.  
  320. EXTERN_API_C( OSStatus )
  321. MPDeleteQueue                    (MPQueueID                 queue);
  322.  
  323. EXTERN_API_C( OSStatus )
  324. MPNotifyQueue                    (MPQueueID                 queue,
  325.                                  void *                    param1,
  326.                                  void *                    param2,
  327.                                  void *                    param3);
  328.  
  329. EXTERN_API_C( OSStatus )
  330. MPWaitOnQueue                    (MPQueueID                 queue,
  331.                                  void **                param1,
  332.                                  void **                param2,
  333.                                  void **                param3,
  334.                                  Duration                 timeout);
  335.  
  336. EXTERN_API_C( OSStatus )
  337. MPSetQueueReserve                (MPQueueID                 queue,
  338.                                  ItemCount                 count);
  339.  
  340.  
  341. /* -------------------------------------------------------------------------------------------*/
  342.  
  343.  
  344. EXTERN_API_C( OSStatus )
  345. MPCreateSemaphore                (MPSemaphoreCount         maximumValue,
  346.                                  MPSemaphoreCount         initialValue,
  347.                                  MPSemaphoreID *        semaphore);
  348.  
  349. EXTERN_API_C( OSStatus )
  350. MPDeleteSemaphore                (MPSemaphoreID             semaphore);
  351.  
  352. EXTERN_API_C( OSStatus )
  353. MPSignalSemaphore                (MPSemaphoreID             semaphore);
  354.  
  355. EXTERN_API_C( OSStatus )
  356. MPWaitOnSemaphore                (MPSemaphoreID             semaphore,
  357.                                  Duration                 timeout);
  358.  
  359.  
  360. #define MPCreateBinarySemaphore(semaphore)    \
  361.             MPCreateSemaphore ( 1, 1, (semaphore) )
  362.  
  363. /* -------------------------------------------------------------------------------------------*/
  364.  
  365.  
  366. EXTERN_API_C( OSStatus )
  367. MPCreateCriticalRegion            (MPCriticalRegionID *    criticalRegion);
  368.  
  369. EXTERN_API_C( OSStatus )
  370. MPDeleteCriticalRegion            (MPCriticalRegionID     criticalRegion);
  371.  
  372. EXTERN_API_C( OSStatus )
  373. MPEnterCriticalRegion            (MPCriticalRegionID     criticalRegion,
  374.                                  Duration                 timeout);
  375.  
  376. EXTERN_API_C( OSStatus )
  377. MPExitCriticalRegion            (MPCriticalRegionID     criticalRegion);
  378.  
  379.  
  380. /* -------------------------------------------------------------------------------------------*/
  381.  
  382.  
  383. EXTERN_API_C( OSStatus )
  384. MPCreateEvent                    (MPEventID *            event);
  385.  
  386. EXTERN_API_C( OSStatus )
  387. MPDeleteEvent                    (MPEventID                 event);
  388.  
  389. EXTERN_API_C( OSStatus )
  390. MPSetEvent                        (MPEventID                 event,
  391.                                  MPEventFlags             flags);
  392.  
  393. EXTERN_API_C( OSStatus )
  394. MPWaitForEvent                    (MPEventID                 event,
  395.                                  MPEventFlags *            flags,
  396.                                  Duration                 timeout);
  397.  
  398.  
  399. /*
  400.    §
  401.    ===========================================================================================
  402.    Timer Services
  403.    ==============
  404. */
  405.  
  406.  
  407. /*
  408.    --------------------------------------------
  409.    ! The timer services are new in version 2.0.
  410. */
  411.  
  412.  
  413. #if 0
  414. /* For now these are taken from DriverServices, should be in a better place.*/
  415. EXTERN_API_C( AbsoluteTime )
  416. UpTime                            (void);
  417.  
  418. EXTERN_API_C( AbsoluteTime )
  419. DurationToAbsolute                (Duration                 duration);
  420.  
  421. EXTERN_API_C( Duration )
  422. AbsoluteToDuration                (AbsoluteTime             time);
  423.  
  424. #endif  /* 0 */
  425.  
  426. enum {
  427.                                                                 /* For MPArmTimer options*/
  428.     kMPPreserveTimerIDMask        = 1L << 0,
  429.     kMPTimeIsDeltaMask            = 1L << 1,
  430.     kMPTimeIsDurationMask        = 1L << 2
  431. };
  432.  
  433.  
  434. EXTERN_API_C( OSStatus )
  435. MPDelayUntil                    (AbsoluteTime *            expirationTime);
  436.  
  437. EXTERN_API_C( OSStatus )
  438. MPCreateTimer                    (MPTimerID *            timerID);
  439.  
  440. EXTERN_API_C( OSStatus )
  441. MPDeleteTimer                    (MPTimerID                 timerID);
  442.  
  443. EXTERN_API_C( OSStatus )
  444. MPSetTimerNotify                (MPTimerID                 timerID,
  445.                                  MPOpaqueID             notificationID,
  446.                                  void *                    notifyParam1,
  447.                                  void *                    notifyParam2,
  448.                                  void *                    notifyParam3);
  449.  
  450. EXTERN_API_C( OSStatus )
  451. MPArmTimer                        (MPTimerID                 timerID,
  452.                                  AbsoluteTime *            expirationTime,
  453.                                  OptionBits             options);
  454.  
  455. EXTERN_API_C( OSStatus )
  456. MPCancelTimer                    (MPTimerID                 timerID,
  457.                                  AbsoluteTime *            timeRemaining);
  458.  
  459.  
  460. /*
  461.    §
  462.    ===========================================================================================
  463.    Memory Services
  464.    ===============
  465. */
  466.  
  467.  
  468. enum {
  469.                                                                 /* Maximum allocation request size is 1GB.*/
  470.     kMPMaxAllocSize                = 1024L * 1024 * 1024
  471. };
  472.  
  473. enum {
  474.                                                                 /* Values for the alignment parameter to MPAllocateAligned.*/
  475.     kMPAllocateDefaultAligned    = 0,
  476.     kMPAllocate8ByteAligned        = 3,
  477.     kMPAllocate16ByteAligned    = 4,
  478.     kMPAllocate32ByteAligned    = 5,
  479.     kMPAllocate1024ByteAligned    = 10,
  480.     kMPAllocate4096ByteAligned    = 12,
  481.     kMPAllocateMaxAlignment        = 16,                            /* Somewhat arbitrary limit on expectations.*/
  482.     kMPAllocateAltiVecAligned    = kMPAllocate16ByteAligned,        /* The P.C. name.*/
  483.     kMPAllocateVMXAligned        = kMPAllocateAltiVecAligned,    /* The older, common name.*/
  484.     kMPAllocateVMPageAligned    = 254,                            /* Pseudo value, converted at runtime.*/
  485.     kMPAllocateInterlockAligned    = 255                            /* Pseudo value, converted at runtime.*/
  486. };
  487.  
  488. enum {
  489.                                                                 /* Values for the options parameter to MPAllocateAligned.*/
  490.     kMPAllocateClearMask        = 0x0001,                        /* Zero the allocated block.*/
  491.     kMPAllocateGloballyMask        = 0x0002,                        /* Allocate from the globally visible pool.*/
  492.     kMPAllocateResidentMask        = 0x0004,                        /* Allocate from the RAM-resident pool.*/
  493.     kMPAllocateNoGrowthMask        = 0x0010                        /* Do not attempt to grow the pool.*/
  494. };
  495.  
  496.  
  497. /* -------------------------------------------------------------------------------------------*/
  498.  
  499.  
  500. EXTERN_API_C( LogicalAddress )
  501. MPAllocateAligned                (ByteCount                 size,
  502.                                  UInt8                     alignment,
  503.                                  OptionBits             options);
  504.  
  505. /* ! MPAllocateAligned is new in version 2.0.*/
  506. EXTERN_API_C( LogicalAddress )
  507. MPAllocate                        (ByteCount                 size);
  508.  
  509. /* Use MPAllocateAligned instead.*/
  510. EXTERN_API_C( void )
  511. MPFree                            (LogicalAddress         object);
  512.  
  513. EXTERN_API_C( ByteCount )
  514. MPGetAllocatedBlockSize            (LogicalAddress         object);
  515.  
  516. /* -------------------------------------------------------------------------------------------*/
  517.  
  518.  
  519. EXTERN_API_C( void )
  520. MPBlockCopy                        (LogicalAddress         source,
  521.                                  LogicalAddress         destination,
  522.                                  ByteCount                 size);
  523.  
  524. EXTERN_API_C( void )
  525. MPBlockClear                    (LogicalAddress         address,
  526.                                  ByteCount                 size);
  527.  
  528. /* ! MPBlockClear is new in version 2.0.*/
  529. EXTERN_API_C( void )
  530. MPDataToCode                    (LogicalAddress         address,
  531.                                  ByteCount                 size);
  532.  
  533. /* ! MPDataToCode is new in version 2.0.*/
  534. /*
  535.    §
  536.    ===========================================================================================
  537.    Exception/Debugging Services
  538.    ============================
  539. */
  540.  
  541.  
  542. /*
  543.    -------------------------------------------------------------------------------------------
  544.    *** Important Note ***
  545.    ----------------------
  546.    
  547.    The functions MPExtractTaskState and MPSetTaskState infer the size of the "info" buffer
  548.    from the "kind" parameter.  A given value for MPTaskStateKind will always refer to a
  549.    single specific physical buffer layout.  Should new register sets be added, or the size
  550.    or number of any registers change, new values of MPTaskStateKind will be introduced to
  551.    refer to the new buffer layouts.  The types for the buffers are in MachineExceptions.
  552.    
  553.    The correspondence between MPTaskStateKind values and MachineExceptions types is:
  554.    
  555.           kMPTaskStateRegisters                -> RegisterInformation
  556.           kMPTaskStateFPU                        -> FPUInformation
  557.           kMPTaskStateVectors                    -> VectorInformation
  558.           kMPTaskStateMachine                    -> MachineInformation
  559.           kMPTaskState32BitMemoryException    -> ExceptionInfo for old-style 32-bit memory exceptions
  560.    
  561.       For reference, on PowerPC the MachineExceptions types contain:
  562.    
  563.           RegisterInformation    -> The GPRs, 32 values of 64 bits each.
  564.           FPUInformation        -> The FPRs plus FPSCR, 32 values of 64 bits each, one value of
  565.                                   32 bits.
  566.           VectorInformation    -> The AltiVec vector registers plus VSCR and VRSave, 32 values
  567.                                   of 128 bits each, one value of 128 bits, and one 32 bit value.
  568.           MachineInformation    -> The CTR, LR, PC, each of 64 bits.  The CR, XER, MSR, MQ,
  569.                                   exception kind, and DSISR, each of 32 bits.  The 64 bit DAR.
  570.           ExceptionInfo        -> Only memory exceptions are specified, 4 fields of 32 bits each.
  571.                                   Note that this type only covers memory exceptions on 32-bit CPUs!
  572. */
  573.  
  574.  
  575. enum {
  576.                                                                 /* Values for the TaskStateKind to MPExtractTaskState and MPSetTaskState.*/
  577.     kMPTaskStateRegisters        = 0,                            /* The task general registers.*/
  578.     kMPTaskStateFPU                = 1,                            /* The task floating point registers*/
  579.     kMPTaskStateVectors            = 2,                            /* The task vector registers*/
  580.     kMPTaskStateMachine            = 3,                            /* The task machine registers*/
  581.     kMPTaskState32BitMemoryException = 4                        /* The task memory exception information for 32-bit CPUs.*/
  582. };
  583.  
  584. enum {
  585.                                                                 /* Option bits and numbers for MPDisposeTaskException.*/
  586.     kMPTaskPropagate            = 0,                            /* The exception is propagated.*/
  587.     kMPTaskResumeStep            = 1,                            /* The task is resumed and single step is enabled.*/
  588.     kMPTaskResumeBranch            = 2,                            /* The task is resumed and branch stepping is enabled.*/
  589.     kMPTaskResumeMask            = 0x0000,                        /* The task is resumed.*/
  590.     kMPTaskPropagateMask        = 1 << kMPTaskPropagate,        /* The exception is propagated.*/
  591.     kMPTaskResumeStepMask        = 1 << kMPTaskResumeStep,        /* The task is resumed and single step is enabled.*/
  592.     kMPTaskResumeBranchMask        = 1 << kMPTaskResumeBranch        /* The task is resumed and branch stepping is enabled.*/
  593. };
  594.  
  595.  
  596. /* -------------------------------------------------------------------------------------------*/
  597.  
  598. EXTERN_API_C( OSStatus )
  599. MPSetExceptionHandler            (MPTaskID                 task,
  600.                                  MPQueueID                 exceptionQ);
  601.  
  602. EXTERN_API_C( OSStatus )
  603. MPThrowException                (MPTaskID                 task,
  604.                                  MPExceptionKind         kind);
  605.  
  606. EXTERN_API_C( OSStatus )
  607. MPDisposeTaskException            (MPTaskID                 task,
  608.                                  OptionBits             action);
  609.  
  610. EXTERN_API_C( OSStatus )
  611. MPExtractTaskState                (MPTaskID                 task,
  612.                                  MPTaskStateKind         kind,
  613.                                  void *                    info);
  614.  
  615. EXTERN_API_C( OSStatus )
  616. MPSetTaskState                    (MPTaskID                 task,
  617.                                  MPTaskStateKind         kind,
  618.                                  void *                    info);
  619.  
  620. /* -------------------------------------------------------------------------------------------*/
  621.  
  622. EXTERN_API_C( OSStatus )
  623. MPRegisterDebugger                (MPQueueID                 queue,
  624.                                  MPDebuggerLevel         level);
  625.  
  626. EXTERN_API_C( OSStatus )
  627. MPUnregisterDebugger            (MPQueueID                 queue);
  628.  
  629.  
  630.  
  631.  
  632. /*
  633.    §
  634.    ===========================================================================================
  635.    Remote Call Services
  636.    ====================
  637. */
  638.  
  639.  
  640. typedef CALLBACK_API_C( void *, MPRemoteProcedure )(void *parameter);
  641. typedef UInt8                             MPRemoteContext;
  642. enum {
  643.     kMPAnyRemoteContext            = 0,
  644.     kMPOwningProcessRemoteContext = 1
  645. };
  646.  
  647.  
  648. EXTERN_API_C( void *)
  649. MPRemoteCall                    (MPRemoteProcedure         remoteProc,
  650.                                  void *                    parameter,
  651.                                  MPRemoteContext         context);
  652.  
  653. /* ! MPRemoteCall is new in version 2.0.*/
  654. /*
  655.    §
  656.    ===========================================================================================
  657.    Checking API Availability
  658.    =========================
  659. */
  660.  
  661.  
  662. /*
  663.    ===========================================================================================
  664.    *** WARNING: You must properly check the availability of MP services before calling them!
  665.    ===========================================================================================
  666.    
  667.    Checking for the availability of the MP API is rather ugly.  This is a historical problem,
  668.    caused by the original implementation letting itself get prepared when it really wasn't
  669.    usable and complicated by some important clients then depending on weak linking to "work".
  670.    (And further complicated by CFM not supporting "deferred" imports, which is how many
  671.    programmers think weak imports work.)
  672.    
  673.    The end result is that the MP API library may get prepared by CFM but be totally unusable.
  674.    This means that if you import from the MP API library, you cannot simply check for a
  675.    resolved import to decide if MP services are available.  Worse, if you explicitly prepare
  676.    the MP API library you cannot assume that a noErr result from GetSharedLibrary means that
  677.    MP services are available.
  678.    
  679.    • If you import from the MP API library you MUST:
  680.    
  681.           Use the MPLibraryIsLoaded macro (or equivalent code in languages other than C) to tell
  682.           if the MP API services are available.  It is not sufficient to simply check that an
  683.           imported symbol is resolved as is commonly done for other libraries.  The macro expands
  684.           to the expression:
  685.    
  686.               ( ( (UInt32)_MPIsFullyInitialized != (UInt32)kUnresolvedCFragSymbolAddress ) &&
  687.                 ( _MPIsFullyInitialized () ) )
  688.    
  689.           This checks if the imported symbol _MPIsFullyInitialized is resolved and if resolved
  690.           calls it.  Both parts must succeed for the MP API services to be available.
  691.    
  692.    • If you explicitly prepare the MP API library you MUST:
  693.    
  694.           Use code similar to the following example to tell if the MP API services are available.
  695.           It is not sufficient to depend on just a noErr result from GetSharedLibrary.
  696.    
  697.               OSErr                        err;
  698.               Boolean                        mpIsAvailable            = false;
  699.               CFragConnectionID            connID                    = kInvalidID;
  700.               MPIsFullyInitializedProc    mpIsFullyInitialized    = NULL;
  701.    
  702.               err    = GetSharedLibrary    ( "\pMPLibrary", kCompiledCFragArch, kReferenceCFrag,
  703.                                         &connID, NULL, NULL );
  704.    
  705.               if ( err == noErr ) {
  706.                   err    = FindSymbol    ( connID, "\p_MPIsFullyInitialized",
  707.                                         (Ptr *) &mpIsFullyInitialized, NULL );
  708.               }
  709.    
  710.               if ( err == noErr ) {
  711.                   mpIsAvailable = (* mpIsFullyInitialized) ();
  712.               }
  713.    
  714.    ===========================================================================================
  715. */
  716.  
  717.  
  718. EXTERN_API_C( Boolean )
  719. _MPIsFullyInitialized            (void);
  720.  
  721. typedef CALLBACK_API_C( Boolean , MPIsFullyInitializedProc )(void );
  722. #define MPLibraryIsLoaded()        \
  723.             ( ( (UInt32)_MPIsFullyInitialized != (UInt32)kUnresolvedCFragSymbolAddress ) &&    \
  724.               ( _MPIsFullyInitialized () ) )
  725. /*
  726.    §
  727.    ===========================================================================================
  728.    Miscellaneous Services
  729.    ======================
  730. */
  731.  
  732.  
  733. EXTERN_API_C( void )
  734. _MPLibraryVersion                (const char **            versionCString,
  735.                                  UInt32 *                major,
  736.                                  UInt32 *                minor,
  737.                                  UInt32 *                release,
  738.                                  UInt32 *                revision);
  739.  
  740. /*
  741.    §
  742.    ===========================================================================================
  743.    Unofficial Services
  744.    ===================
  745. */
  746.  
  747.  
  748. /*
  749.    ===========================================================================================
  750.    *** WARNING ***
  751.    These services are not part of the officially documented multiprocessing API.  They may not
  752.    be avaliable in future versions of Mac OS multiprocessing support, or in environments that
  753.    have a different underlying OS architecture such as Mac OS on top of a microkernel, the
  754.    Mac OS Blue Box under Mac OS X, native MP support in Mac OS X, etc.
  755.    ===========================================================================================
  756. */
  757.  
  758.  
  759. EXTERN_API_C( LogicalAddress )
  760. _MPAllocateSys                    (ByteCount                 size);
  761.  
  762. /* Use MPAllocateAligned instead.*/
  763. EXTERN_API_C( void *)
  764. _MPRPC                            (MPRemoteProcedure         remoteProc,
  765.                                  void *                    parameter);
  766.  
  767. /* Use _MPRemoteCall instead.*/
  768. EXTERN_API_C( Boolean )
  769. _MPTaskIsToolboxSafe            (MPTaskID                 task);
  770.  
  771. EXTERN_API_C( Boolean )
  772. _MPLibraryIsCompatible            (const char *            versionCString,
  773.                                  UInt32                 major,
  774.                                  UInt32                 minor,
  775.                                  UInt32                 release,
  776.                                  UInt32                 revision);
  777.  
  778.  
  779. #define    MPRPC                    _MPRPC
  780. #define    MPTaskIsToolboxSafe        _MPTaskIsToolboxSafe
  781.  
  782. /*
  783.    §
  784.    ===========================================================================================
  785.    Defunct Services
  786.    ================
  787. */
  788.  
  789.  
  790. #ifndef MPIncludeDefunctServices
  791. #define MPIncludeDefunctServices 0
  792. #endif  /* !defined(MPIncludeDefunctServices) */
  793.  
  794. #if MPIncludeDefunctServices
  795. EXTERN_API_C( void )
  796. _MPDebugStr                        (ConstStr255Param         msg);
  797.  
  798. EXTERN_API_C( StringPtr )
  799. _MPStatusPString                (OSStatus                 status);
  800.  
  801. EXTERN_API_C( const char *)
  802. _MPStatusCString                (OSStatus                 status);
  803.  
  804.  
  805. #include <stdarg.h>
  806. typedef CALLBACK_API_C( void , MPPrintfHandler )(MPTaskID taskID, const char *format, va_list args);
  807. EXTERN_API_C( void )
  808. _MPInitializePrintf                (MPPrintfHandler         pfn);
  809.  
  810. EXTERN_API_C( void )
  811. _MPPrintf                        (const char *            format,
  812.                                  ...);
  813.  
  814. #endif  /* MPIncludeDefunctServices */
  815.  
  816. /* ===========================================================================================*/
  817.  
  818.  
  819.  
  820.  
  821. #if PRAGMA_STRUCT_ALIGN
  822.     #pragma options align=reset
  823. #elif PRAGMA_STRUCT_PACKPUSH
  824.     #pragma pack(pop)
  825. #elif PRAGMA_STRUCT_PACK
  826.     #pragma pack()
  827. #endif
  828.  
  829. #ifdef PRAGMA_IMPORT_OFF
  830. #pragma import off
  831. #elif PRAGMA_IMPORT
  832. #pragma import reset
  833. #endif
  834.  
  835. #ifdef __cplusplus
  836. }
  837. #endif
  838.  
  839. #endif /* __MULTIPROCESSING__ */
  840.  
  841.